package com.wabbei.friendcenter.action;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;

public class PrivateTalkSWFUploadAction {
		private String toName;
		private File file;
		private String fileFileName;
	
		public String getFileFileName() {
			return fileFileName;
		}


		public void setFileFileName(String fileFileName) {
			this.fileFileName = fileFileName;
		}


		public String getToName() {
			return toName;
		}


		public void setToName(String toName) {
			this.toName = toName;
		}


		public File getFile() {
			return file;
		}


		public void setFile(File file) {
			this.file = file;
		}


		public String filesUpload(){
			// return the fileFileName
			fileFileName=ReNameUtil.GetNewName()+fileFileName.substring(fileFileName.indexOf("."),fileFileName.length());
			System.out.println(toName+";;;"+fileFileName);
			if(file!=null){
				String realPath=ServletActionContext.getServletContext().getRealPath("/"+toName);
				//System.out.println();
				File newFile=new File(realPath);
				if(!newFile.exists()){
					newFile.mkdirs();
				};
				try {
					FileUtils.copyFile(file,new File(newFile,fileFileName));
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				System.out.println("send file successful");
				try {
					ServletActionContext.getResponse().getWriter().write(fileFileName);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
				return null;
		}
}
